package cn.yotta.user.core.web.component;

import cn.yotta.user.api.params.user.UserFindByTokenRequest;
import cn.yotta.user.api.vo.UserVo;
import cn.yotta.user.core.server.service.LoginService;
import cn.yotta.user.web.autoconfiguration.provider.LoginUser;
import cn.yotta.user.web.autoconfiguration.provider.UserReadFromTokenProvider;
import cn.yotta.user.web.autoconfiguration.provider.impl.AbstractYottaUserReadProvider;

import java.util.Objects;

/**
 * @author wyaoyao
 * @date 2023/3/11 21:50
 * 对于用户服务，就不需要通过rpc调用获取登录用户，直接本地调用即可
 * 特此实现本地读取登录用户
 */
public class LocalUserReadFromTokenProvider extends AbstractYottaUserReadProvider {


    private final LoginService loginService;

    public LocalUserReadFromTokenProvider(LoginService loginService) {
        this.loginService = loginService;
    }


    @Override
    protected UserVo doFindUserByToken(UserFindByTokenRequest findByTokenRequest) {
        return loginService.getLoginUser(findByTokenRequest);
    }
}
